<%-- 
    Document   : login
    Created on : Nov 6, 2011, 3:26:50 PM
    Author     : Felipe
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Admin: Login</title>
    </head>
    <body>
        <%
            if (session.getAttribute("access_type") != null) {
                pageContext.forward("./home.jsp");
                return;
            }
            boolean error_auth = false;
            if (request.getParameter("enviar") != null) {
                // processa login
                String name = request.getParameter("usuario");
                String senha1 = request.getParameter("senha1");
                String senha2 = request.getParameter("senha2");
                boolean login_valido = false;
                // metodo valida deve ser implementado
                if (login_valido) {
                    session.setAttribute("access_type", "admin");
                    session.setAttribute("name", name);
                    session.setAttribute("id", 0);
                    pageContext.forward("./home.jsp");
                    session.setAttribute("usuario", name);
                } else {
                    error_auth = true;
                }
            }
            // show login form
        %>
        <table WIDTH=800 align=center>
            <tr height=80 align=center><td colspan=2><img src="./../images/Logo.png" width=600 align=center/></a></td></tr>
            <tr align=center><td colspan=2><h2>Admin login page. Please enter your data below ...</h2></td></tr>
            <form method="get" action="./login.jsp">
                <% if (error_auth) {
                %><tr align=center><td colspan=2><font color=red>Incorrect email and/or password!</font></td></tr>
                        <% }%>
                <tr><td width=340 align=right>email:</td><td align=left><input type="text" name="email"/></td></tr>
                <tr><td align=right>senha1:</td><td align=left><input type="password" name="senha1"/></td></tr>
                <tr><td align=right>senha2:</td><td align=left><input type="password" name="senha2"/></td></tr>
                <tr><td colspan=2 align=center><input type="submit" name="enviar" value="Enviar" style="width:220px"/></td></tr>
        </table>
    </form>
</tr>
</table>
</body>
</html>
